#!/usr/bin/perl

# $Id: 20_buildcommand.t 283 2010-07-18 14:29:00Z dolbanavt $
# $Date: 2010-07-18 17:29:21 +0300 (Вск, 18 Июл 2010) $
# $HeadURL: https://robosearch.googlecode.com/svn/branches/reborn/t/20_buildcommand.t $
# $LastChangedRevision$

use FindBin qw( $RealBin );
use File::Spec::Functions qw( catfile );

BEGIN {
    push @INC, catfile( $RealBin, '..', 'base_lib' );
    push @INC, catfile( $RealBin, '..', 'lib' );
}

use JIP::ToolSet;
use English qw( -no_match_vars );
use Test::More 0.88;
use Const::Fast qw( const );
use Test::Exception;

const my $MODULE => 'BuildCommand';

use_ok $MODULE;
require_ok $MODULE;

can_ok $MODULE, qw(
    new _init
    get_conf get_log get_dbh
    set_conf set_log set_dbh
    execute
    _log_step_header
);

throws_ok { $MODULE->new(); }
    qr{^Required\soption\s'conf'\sis\snot\sprovided}xms,
    'new( conf )';

throws_ok { $MODULE->new( conf => q{} ); }
    qr{^Required\soption\s'log'\sis\snot\sprovided}xms,
    'new( log )';

throws_ok { $MODULE->new( conf => q{}, log => q{} ); }
    qr{^Required\soption\s'dbh'\sis\snot\sprovided}xms,
    'new( dbh )';

my $o = $MODULE->new(
    conf => 'conf_object',
    log  => 'logger',
    dbh  => 'database_wrapper',
);

ok $o, 'got object';

isa_ok $o, $MODULE;
isa_ok $o, 'JIP::BaseClass';
isa_ok $o, 'Class::Accessor::Fast';

is $o->get_conf, 'conf_object',      'conf accessor';
is $o->get_log,  'logger',           'log accessor';
is $o->get_dbh,  'database_wrapper', 'dbh accessor';

throws_ok { $o->execute(); }
    qr{^execute\(\)\sis\sabstract\smethod}xms,
    'execute() - abstract method';

throws_ok { $o->_log_step_header(); }
    qr{^step_name\srequired}xms,
    '_log_step_header( name )';

done_testing();
